package Example;
//打印菱形

import java.util.Scanner;

public class Demo16 {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.out.println("请输入打印的菱形的行数（是个奇数）：");
        int high = s.nextInt();
        if (high % 2 == 0 && high <= 0) {
            System.out.println("输入有误");
        } else {
            int temp = (high + 1) / 2;
            System.out.println("图形如下------");
            // ------------打印菱形的上半部分---------------
            for (int i = 1; i <= temp; i++) {
                for (int j = temp; j > i; j--) {
                    System.out.print(" ");
                }
                for (int k = 1; k <= i; k++) {
                    System.out.print("* ");
                }
                System.out.println();
            }
            // -------------打印菱形的下半部分--------------
            for (int i = 1; i <= temp - 1; i++) {
                for (int j = 1; j <= i; j++) {
                    System.out.print(" ");
                }
                for (int k = temp - 1; k >= i; k--) {
                    System.out.print("* ");
                }
                System.out.println();
            }
        }
    }
}
